package com.example.carrierapp.ui.main.tender.yes;

import android.content.Context;

import com.example.carrierapp.base.BasePresenter;
import com.example.carrierapp.bean.tender.TenderListBean;
import com.example.carrierapp.net.ApiMiddleHelper;
import com.example.carrierapp.net.listener.DataCallBackListener;
import com.example.carrierapp.util.LogUtil;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;

import java.util.HashMap;
import java.util.Map;

import io.reactivex.Flowable;

public class TenderYesPresenter extends BasePresenter<TenderYesContract.View> implements TenderYesContract.Presenter {
    private Context mContext;
    public TenderYesPresenter(Context context) {
        mContext=context;
    }

    @Override
    public void start() {

    }

    @Override
    public void tenderList(boolean isWin, int skipCount) {
        Map<String, String> biddingMap = new HashMap<>();
        biddingMap.put("maxResultCount", "10");
        biddingMap.put("isWin", isWin + "");
        biddingMap.put("skipCount", skipCount + "");
        Flowable<JsonObject> flowable = apiStrores.tenderList(biddingMap);

        LogUtil.d("tenderList-" + isWin + "-" + skipCount);
        ApiMiddleHelper.getInstance().toNetIo2Main(mContext,flowable, new DataCallBackListener() {

            @Override
            public void onSuccess(String json) {
                LogUtil.d("tenderList-onSuccess-" + json);

                TenderListBean bean = new Gson().fromJson(json, new TypeToken<TenderListBean>() {
                }.getType());
                if (getView() != null) {
                getView().tenderListSuccess(bean);

                }
            }

            @Override
            public void onFailure(String msg) {
                LogUtil.d("tenderList-onFailure-" + msg);
                getView().tenderListFailde(msg);
            }
        });
    }
}
